#ifndef ITEMCOLOR_H
#define ITEMCOLOR_H

#include "config/ConfigItem.h"
#include <QColor>
#include <QWidget>

class ItemColor : public ConfigItem {
    Q_OBJECT
public:

    QColor get()
    {
        return m_data;
    }
    void set(const QColor &value)
    {
        m_data = value;
        emit itemEdited();
    }
protected:
    QWidget *createWidget(WidgetStyle s) override;
    void update(QWidget *widget, UpdateOption option) override;
    void writeToData(QDataStream &stream) const override;
    void readFromData(QDataStream &stream) override;
private:
    QColor m_data = Qt::white;
};


class ColorPicker : public QWidget {
    Q_OBJECT
public:
    ColorPicker(QWidget *parent = nullptr) : QWidget(parent)
    {
        setMinimumSize(120, 30);
    }
    void setColor(const QColor &value)
    {
        m_color = value;
        update();
    }
    QColor getColor()
    {
        return m_color;
    }
protected:
    void pickColor();
    void paintEvent(QPaintEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
private:
    QColor m_color = Qt::white;
    int radius = 20;
    bool mouseOnColor = false;

signals:
    void colorPicked(QColor color);
};

#endif // ITEMCOLOR_H
